﻿using B.S.BaseData.Api.Read.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Read.CommandHandler.GoodsCommandHandler
{
    public class GoodsvendorAccessoriesCommandHandler : IRequestHandler<GoodsvendorAccessoriesCommand, APIResult<GoodsvendorAccessories>>
    {
        private readonly IBaseRepository<GoodsvendorAccessories> _scultivationCompanybaseRepository;
        public GoodsvendorAccessoriesCommandHandler(IBaseRepository<GoodsvendorAccessories> scultivationCompanybaseRepository)
        {
            _scultivationCompanybaseRepository = scultivationCompanybaseRepository;
        }
        public async Task<APIResult<GoodsvendorAccessories>> Handle(GoodsvendorAccessoriesCommand request, CancellationToken cancellationToken)
        {
            APIResult<GoodsvendorAccessories> result = new APIResult<GoodsvendorAccessories>();
            try
            {
                var list = await _scultivationCompanybaseRepository.GetValues(x => x.GoodsId == request.Id);
                result.Data = list;
                result.Msg = "辅料信息显示成功";
                result.Code = ApiEnum.Success;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Msg = "辅料信息显示失败";
                result.Code = ApiEnum.Fail;
                return await Task.FromResult(result);
            }
        }
    }
}
